package com.miracle.mango.component.security;

import com.alibaba.fastjson.JSON;
import com.miracle.mango.util.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description:
 * @author: wangxf
 * @date: Created in 2020/8/23 15:34
 */
@Slf4j
@Component
public class AjaxAuthenticationFailureHandler implements AuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
        ResultBody responseBody = new ResultBody();
        responseBody.setCode("400");
        responseBody.setMessage("Login Failure!");
        response.getWriter().write(JSON.toJSONString(responseBody));
    }

}
